//$(document).on('touchmove',function(ev){ ev.preventDefault() });
member_obj={
    source_init:function(){
        tools.scroll_event();
        tools.back_event();
    },
    account_init:function(){
        //tools.logout();
        /*$('.address').click(function(){
            $.post('/member/show_address_action/',{},function(data){
                if(data.ret==1){
                    tools.alert(data.msg);
                }
            },'json');
        });*/
        $('.source').click(function(){
            $.post('/member/show_source_action/',{},function(data){
                if(data.ret==1){
                    tools.alert('当前积分：'+data.msg.source+'分<br>'+data.msg.str);
                }
            },'json');
        });
        $('input[name="upload"]').change(function(){
            $('#sub_form').submit();
        });
        $(window).load(function(){
           //new IScroll({wrapper: $('#main_content'),scroller: $('#scroller'),bounce:false});
        });
    },
    cart_init:function(){
        tools.scroll_event();
        tools.back_event();
        $('.del').click(function(){
            var CId=$(this).attr('CId');
            tools.alert('你确定删除该项吗？',function(){
                $.post('/member/del_cart_action',{
                    'CId'   : CId
                },function(data){
                    if(data.ret==1){
                        window.location.reload();
                    }
                },'json');
            },1);
        });
        $('.cart_btn').click(function(){
            var group_CartId_str = $('input[name="cart"]').val();
            if(!group_CartId_str){
                tools.alert('请选择产品');
                return;
            }
            $.post('/member/select_cart_action/',{
                'group_CartId_str'  : group_CartId_str
            },function(data){
                if(data.ret==1){
                    //跳转
                    window.location.href = '/member/order/';
                }
            },'json')
        });
        //全选店铺购物车
        $('.shop_section .round').click(function(){
            var shop_MemberId=$(this).attr('shop_MemberId');
            var flag = $(this).attr('flag');
            flag = flag==1?0:1;
            if(flag){
                $('.info_section[shop_MemberId='+shop_MemberId+']').find('.round').addClass('active').attr('flag',1);
                $(this).addClass('active');
                $(this).attr('flag',1);
            } else {
                $('.info_section[shop_MemberId='+shop_MemberId+']').find('.round').removeClass('active').attr('flag',0);
                $(this).removeClass('active');
                $(this).attr('flag',0);
            }
            make_cart_id();
            $.post('/member/select_action/',{
                'shop_MemberId' : shop_MemberId,
                'value'         : flag,
                'type'          : 'shop'
            },function(data){

            },'json');
        });
        //单选产品
        $('.info_section .round').click(function(){
            var CId  = $(this).attr('CId');
            var flag = $(this).attr('flag');
            flag = flag==1?0:1;
            if(flag){
                $(this).addClass('active');
                $(this).attr('flag',1);
            } else {
                $(this).removeClass('active');
                $(this).attr('flag',0);
            }
            make_cart_id();
            $.post('/member/select_action/',{
                'CId'  : CId,
                'value': flag,
                'type': 'cart'
            },function(data){

            },'json');
        });
        //全选
        $('.all_round').click(function(){
            var flag = $(this).attr('flag');
            flag = flag==1?0:1;
            if(flag){
                $(this).addClass('active');
                $(this).attr('flag',1);
                $('.round').addClass('active');
                $('.round').attr('flag',1);
            } else {
                $(this).removeClass('active');
                $(this).attr('flag',0);
                $('.round').removeClass('active');
                $('.round').attr('flag',0);
            }
            make_cart_id();
            $.post('/member/select_action/',{
                'type'  : 'all',
                'value' : flag
            },function(data){

            },'json');
        });
        //删除一个
        $('.del_cart').click(function(){
            var CId     = $(this).attr('CId');
            var shop_MemberId = $(this).attr('shop_MemberId');
            tools.alert('您确定删除该项吗？',function(){
                $.post('/member/del_cart_action/',{
                    'CId'           : CId
                },function(data){
                    if(data.ret=1){
                        $('#cart_product_'+CId).remove();
                        if(!$('.info_section[shop_MemberId='+shop_MemberId+']').size()){
                            $('#shop_member_'+shop_MemberId).remove();
                        }
                        if(data.msg=='0'){
                            window.location.reload();
                        }
                    }
                },'json')
            },1);
        });
        //全部删除
        $('.del_all').click(function(){
            var shop_MemberId = $(this).attr('shop_MemberId');
            tools.alert('您确定删除该项吗？',function(){
                $.post('/member/del_cart_action/',{
                    'shop_MemberId' : shop_MemberId
                },function(data){
                    if(data.ret=1){
                        $('#shop_member_'+shop_MemberId).remove();
                        if(data.msg=='0'){
                            window.location.reload();
                        }
                    }
                },'json')
            },1);
        });
        function make_cart_id(){ //构造cartid
            var group_CId_ary = []
            var group_CId_str = '';
            $('.info_section').find('.round[flag=1]').each(function(k,v){
                group_CId_ary.push($(v).attr('CId'));
            })
            group_CId_str=group_CId_ary.join('|');
            $('input[name=cart]').val(group_CId_str);
        }
    },
    order_init:function(){
        tools.scroll_event();
        tools.back_event();
		$('.form_section .rows .pay').click(function(){
			$(this).addClass('on').siblings('.form_section .rows .pay').removeClass('on');
			$('#pay').val($(this).attr('value'));
		});	
		$('.form_section .rows .it').click(function(){
			$(this).addClass('on').siblings('.form_section .rows .it').removeClass('on');
			$('#shipping').val($(this).find('font').html());
		});		
        tools.validate($('#sign_in_form'),function(data){
            tools.alert('操作成功',function(){
                window.location.href = '/member/order_list/';
            });
        }, function(data){
            tools.alert(data.msg);
        });
    },
    order_list_init:function(){
        tools.scroll_event();
        tools.back_event();
        $('.tab_frame .title').click(function(){

        });
    },
    wish_list_init:function(){
        tools.scroll_event();
        tools.back_event();
        //切换
        $('.tab_frame .title').click(function(){
            var type=$(this).attr('type');
            $('.tab_frame .title').removeClass('active_1');
            $('.tab_frame .title .word').removeClass('active_0');
            $(this).addClass('active_1');
            $(this).find('.word').addClass('active_0');
            if(type=='0'){
                $('.seller_list').hide();
                $('.product_list_frame').show();
            } else {
                $('.seller_list').show();
                $('.product_list_frame').hide();
            }
        });
    },
    password_init:function(){
        tools.back_event();
		$('.sex span').click(function(){
			$(this).addClass('on').siblings().removeClass('on');	
			$('input[name=Sex]').val($(this).index('.sex span'));
			$('input[name=Title]').val($(this).index('.sex span'));
		});
        tools.validate($('#sign_in_form'),function(data){
            window.location.href = '/member/password/';
        }, function(data){
            tools.alert(data.msg);
        });
    },
	address_init:function(){
		tools.scroll_event();
        tools.back_event();
		tools.validate($('#address_form'),function(data){
            tools.alert('操作成功',function(){
                window.location.href = '/member/address_list/';
            });
        }, function(data){alert('不行');
            tools.alert(data.msg);
        });
	}
}